import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
import { request } from '@/utils/request'

/**
 * 账号登录
 * @param mobile 手机号
 * @param password 密码
 */
export const loginByPassword = (mobile: string, password: string) =>
  request<User>('/login/password', 'POST', { mobile, password })

/**
 * 发送登录时候的验证码
 * @param mobile 手机号
 * @param type 密码
 */
export const sendMobileCode = (mobile: string, type: CodeType) =>
  request<{ code: string }>('/code', 'GET', { mobile, type })

/**
 * 验证码登录
 * @param mobile 手机号
 * @param code 验证码
 */
export const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

/**
 * 获取用户信息
 */
export const getUserInfo = () => request<UserInfo>('/patient/myUser')

/**
 * 获取患者列表
 */
export const getPatientList = () => request<PatientList>('/patient/mylist')

/**
 * 添加患者信息
 * @param patient 对象
 */
export const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)

/**
 * 编辑患者
 * @param patient 对象
 */
export const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

/**
 * 删除患者
 * @param id 患者 ID
 */
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

/**
 * 获取患者详情
 * @param id 患者 ID
 */
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)
